package com.hspedu.homework01;

public class Homework01 {
    public static void main(String[] args) {
        String s = "abcdefghijk";
        String s1 = null;
        try {
            s1 = reverse(s,9,6);
        } catch (Exception e) {
            System.out.println(e.getMessage());
            return;
        }
        System.out.println(s1);
    }

    public static String reverse(String str, int start, int end){
        if(!(str!=null && start > 0 && end < str.length() && start < end)){
            throw new RuntimeException("argument is wrong");
        }
        StringBuffer sb = new StringBuffer(str);
        for (int i = start; i <(start + end)/2; i++) {
            int rev = end - i + start;
            char temp = sb.charAt(i);
            sb.setCharAt(i,sb.charAt(rev));
            sb.setCharAt(rev,temp);
        }
        return sb.toString();
    }
}

